package stackdemo;

import java.util.Stack;

public class Node {
    public Node next;
    public int val;
    public Node(int val) {
        this.val = val;
        this.next = null;
    }
    void printlist(Node head){
        if(head!=null){
            printlist(head.next);
            System.out.print(head.val+" ");
        }
    }
    void stackPrintList(Node head){
        if(head==null){
            return;
        }
        Stack<Node> stack=new Stack<>();
        Node cur=head;
        while (cur!=null){
            stack.push(cur);
            cur=cur.next;
        }
        while (!stack.empty()){
            System.out.print(stack.pop().val+" ");
        }
    }
}
